<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ShowCondition</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<SCRIPT language="javascript">
function _isEmpty(){return chkEmpty.checked}
</SCRIPT>
<body onload="page_Load()" MS_POSITIONING="GridLayout" topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0" bgcolor="menu" scroll="no">
<TABLE width="100%" style="FONT:menu;BACKGROUND-COLOR:menu" border="0">
	<TR>
		<TD width="1%" rowspan="3" height="100%" rowspan="3">
			<SELECT id="selField" size="15" style="FONT-WEIGHT:bold; FONT-SIZE:8pt; FONT-FAMILY:monospace" datasrc="#xmlSrc" datafld="ColumnID"
							onchange="setUnits(this)">
				<ASP:LITERAL ID="ltrField" Runat="server"></ASP:LITERAL>
			</SELECT>
		</TD>
		<TD>&nbsp;</TD>
		<TD>&nbsp;</TD>
		<TD>&nbsp;
			<BR>
			<BR>
			<BR>
			<BR>
</TD>
	</TR>
	<TR valign="bottom">
		<TD width="1%" height="20%">
			<SELECT id="selCond" datasrc="#xmlSrc" datafld="Condition" runat="server" onchange="setTimeout('try{txtCondValue.focus()}catch(e){}',100)" NAME="selCond">
			</SELECT>
		</TD>
		<TD width="1%" nowrap>
			<INPUT id="txtCondValue" size="4" datasrc="#xmlSrc" datafld="Value" onfocus="this.select()"
						 onkeydown="doCondValue_KeyDown(this);if(event.keyCode==13 && hideValue1())event.cancelBubble=true;"
						 onkeypress="if(event.keyCode==13 && hideValue1()){this.blur();setTimeout('btnAddCond.click()',100)}">
			<INPUT id="txtCondValue1" size="4" datasrc="#xmlSrc" datafld="Value1" onfocus="this.select()"
						 onkeydown="doCondValue_KeyDown(this);event.cancelBubble=true"
						 onkeypress="if(event.keyCode==13){this.blur();setTimeout('btnAddCond.click()',100)}">
			<SELECT id="selCondValue" datasrc="#xmlSrc" datafld="Value" runat="server" onchange="changeSelectValue(this)" style="display:none" NAME="selCondValue"></SELECT>
			<SELECT id="selCondValue1" datasrc="#xmlSrc" datafld="Value1" runat="server" onchange="changeSelectValue(this)" style="display:none" NAME="selCondValue1"></SELECT>
		<TD width="100%" nowrap>
			<SPAN id="spnUnits" style="PADDING-BOTTOM: 5px; WIDTH: 50px"></SPAN>
	</TR>
	<TR>
		<TD>&nbsp;</TD>
		<TD valign="top" nowrap>
			<FORM style="padding:0px;margin:0px" id="frm">
			<INPUT type="radio" id="chkDoAnother1" name="chkDoAnother" value="1"> <LABEL for="chkDoAnother1">Do Another</LABEL><BR>
			<INPUT type="radio" id="chkDoAnother2" name="chkDoAnother" value="4"> <LABEL for="chkDoAnother2">Do Child</LABEL>
			</FORM>
			<BR>
		</TD>
		<TD>&nbsp;</TD>
	</TR>
</TABLE>
<DIV id="divFieldDesc" style="MARGIN-BOTTOM:5px;MARGIN-LEFT:0px;WIDTH:100%;MARGIN-RIGHT:0px;BACKGROUND-COLOR:lemonchiffon"></DIV>
<TABLE width="100%" cellpadding="0" cellspacing="0"><TR>
	<TD width="1%" nowrap>Container <INPUT type="checkbox" id="chkEmpty" datasrc="#xmlSrc" datafld="IsEmpty" onclick="setTimeout('try{txtLabel.focus()}catch(e){}',200)">
	<TD width="100%" align="center">
		<TEXTAREA id="txtLabel" datasrc="#xmlSrc" datafld="Label" style="display:expression(_isEmpty()?'':'none');width:94%;border:1 solid black;overflow-y:visible;overflow-x:visible"
					 onkeypress1="if(event.keyCode==13){this.blur();setTimeout('btnAddCond.click()',100)}"
		></TEXTAREA>
</TABLE>
</DIV>
<CENTER>
	<INPUT type="button" value=" Add " id="btnAddCond"
					onclick="addGLCondition()"
					>
	<INPUT type="button" value="Close" onclick="window.close()">
</CENTER>
<XML id="xmlSrc">
	<ASP:LITERAL ID="ltrSrc" Runat="server"></ASP:LITERAL>
</XML>
<XML id="xmlUnitEnums"><ASP:LITERAL Runat="server" ID="ltrUnitEnums"></ASP:LITERAL></XML>
<SCRIPT language="javascript" src="/include/common.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/SOAP.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/RDS.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/XML.js"></SCRIPT>
<SCRIPT language="javascript" src="Common/GLRules.js"></SCRIPT>
<SCRIPT language="javascript">
setTimeout('\
selField.setExpression("disabled","_isEmpty()");\
selCond.setExpression("disabled","_isEmpty()");\
selCondValue.setExpression("disabled","_isEmpty()");\
selCondValue1.setExpression("disabled","selCondValue.disabled");\
txtCondValue.setExpression("disabled","_isEmpty()");\
txtCondValue1.setExpression("disabled","txtCondValue.disabled");\
',1000);
initWS("GLRules","GLRules.asmx");
selCond.attachEvent("onchange",showValue1);
attachToKeyDown();
function doCondValue_KeyDown(el){
	var innerNumber = new Number(el.value || "0");
	if( event.keyCode == 38 && !isNaN(innerNumber)){el.value = formatRate(parseFloat(el.value)+0.125);event.cancelBubble=true;return;}
	if( event.keyCode == 40 && !isNaN(innerNumber)){el.value = formatRate(parseFloat(el.value)-0.125);event.cancelBubble=true;return;}
}
function showValue1(){
	if( hideValue1() )rsField(selCondValue1,selCondValue1.dataFld).value = "";
	selCondValue1.style.display = hideValue1() ? "none" : selCondValue.style.display;
	txtCondValue1.style.display = hideValue1() ? "none" : txtCondValue.style.display;
	cropWindow();
}
var editElement = dialogArguments.editElement;
var ruleID = getParam("RuleID")||null;
var programID = getParam("ProgramID")||null;
var mode = getParamInt("mode");
var parentID = getParam("ParentID")||null;
if( !mode )alert("Mode is missing!\n\nUse: \tmode=1 - insert\n\tmode=2 - combine\n\tmode=3 - edit\n\tmode=4 - inser child");
if( (mode == MODE_INSERT || mode == MODE_COMBINE || mode == MODE_INSERT_CHILD) && !ruleID )alert("RuleID is missing!");
var title = new Array("Insert","Combine","Update","Insert Child");
btnAddCond.value = title[mode-1];
function page_Load(){
	cropWindow();
	setTimeout("setUnits(selField)",100);
	try{
		if( selField.selectedIndex >= 0 )txtCondValue.focus();
		else selField.focus();
	}catch(e){}
}
function setUnits(sel){
	var onChange = sel.onchange; sel.onchange = null;
	var selIndex = sel.selectedIndex; sel.selectedIndex += 7;	sel.selectedIndex = selIndex;
	sel.onchange = onChange;
	setUnits_(sel);
}
function setUnits_(sel){
	if( sel.selectedIndex < 0 )return;
	divFieldDesc.innerHTML=unescape(getSELAttr(sel,'desc'));
	var htmlUnits = unescape('('+getSELAttr(sel,'units')+')');
	if( spnUnits.innerHTML == htmlUnits )return;
	spnUnits.innerHTML = htmlUnits;
	try{
		fillSelect(xmlUnitEnums.recordset(getSELAttr(sel,'enumTable')).Value,selCondValue,"Name","ID");
		fillSelect(xmlUnitEnums.recordset(getSELAttr(sel,'enumTable')).Value,selCondValue1,"Name","ID","");
		txtCondValue.style.display = txtCondValue1.style.display = "none";
		selCondValue.style.display = "";
		selCondValue1.style.display = hideValue1() ? "none" : "";
	}catch(e){
		txtCondValue.style.display =  "";
		txtCondValue1.style.display = hideValue1() ? "none" : "";
		selCondValue.style.display = selCondValue1.style.display = "none";
	}
	var ds=selCondValue.dataSrc;
	selCondValue.dataSrc=selCondValue1.dataSrc="";
	selCondValue.dataSrc=selCondValue1.dataSrc=ds;
}
function addGLCondition(){
	var rs = xmlSrc.recordset;
	var columnID = _isEmpty()?0:rs("columnID").value;
	var condition = _isEmpty()?"":encodeXML(rs("Condition").value);
	var value = _isEmpty()?"":encodeXML(rs("value").value);
	var value1 = _isEmpty()?"":rs("value1").value;
	var label = !_isEmpty()?null:encodeXML(rs("Label").value);
	switch(mode){
		case MODE_EDIT: // Edit
			var ret = WS(CO("UpdateGLCondition"),ruleID,columnID,condition,value,value1,label);
			break;
		case MODE_INSERT: // Insert
			var ret = WS(CO("InsertGLCondition"),programID,parentID,ruleID,columnID,condition,value,value1,label);
			break;
		case MODE_INSERT_CHILD: // Insert Child Rule
			var ret = WS(CO("InsertGLCondition"),null,ruleID,null,columnID,condition,value,value1,label);
			break;
		case MODE_COMBINE: // Combine
			var ret = WS(CO("CombineGLCondition"),ruleID,columnID,condition,value,value1,label);
			break;
		default:
			alert("Unknown mode:"+mode);
			return;
	}
	if( showSOAPError(ret) )return;
	returnValue = {
		columnID:eval(columnID),
		condition:condition,
		value:value,value1:value1,
		valueEnum:selCondValue.selectedIndex<0?value:selCondValue[selCondValue.selectedIndex].text,
		valueEnum1:selCondValue1.selectedIndex<0?value:selCondValue1[selCondValue1.selectedIndex].text,
		ruleID:ret.value,
		doAnother:(frm.chkDoAnother1.checked ? frm.chkDoAnother1 : frm.chkDoAnother2.checked ? frm.chkDoAnother2 : {}).value
	};
	window.close();	
}
function changeSelectValue(sel){return
	if( editElement )setTimeout("addGLCondition()",100);
}
function getSELAttr(sel,attrName){return sel[sel.selectedIndex].getAttribute(attrName)}
function hideValue1(){return selCond.value != "OR" && selCond.value != "BETWEEN"}

</SCRIPT>
</body>
</HTML>
